package org.wqp.redisson.utils;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.io.File;
import java.io.IOException;

public class RedissonUtil {

    private static volatile boolean init = false;
    private static RedissonClient redisson;

    public static void init() {
        if (!init) {
            init = true;
            try {
                Config config = Config.fromYAML(new File("E:\\idea-workspace1\\redisson-test\\src\\main\\resources\\redisson-config.yml"));
                redisson = Redisson.create(config);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

    public static RedissonClient getRedissonClient() {
        if (!init) {
            init();
        }
        return redisson;
    }

    public static void shutdown() {
        if (redisson != null) {
            redisson.shutdown();
        }
    }

}
